package p270jp.pxv.android.legacy.upload.presentation.view;

import android.content.Context;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.android.flexbox.FlexboxLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import p014ae.View$OnClickListenerC0156s7;
import p014ae.View$OnClickListenerC0158t;
import p064c6.Preconditions;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView;
import p270jp.pxv.android.legacy.view.AddButton;
import p325m0.MutabilityOwnership;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p470ri.HashtagService;
import p519tf.InputSpaceFilter;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p603wm.Unit;

/* compiled from: WorkTagEditView.kt */
/* renamed from: jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView */
/* loaded from: classes2.dex */
public final class WorkTagEditView extends ConstraintLayout implements AbstractC5475a {

    /* renamed from: z */
    public static final /* synthetic */ int f19087z;

    /* renamed from: t */
    public final FlexboxLayout f19089t;

    /* renamed from: u */
    public final AddButton f19090u;

    /* renamed from: v */
    public final EditText f19091v;

    /* renamed from: w */
    public final LayoutInflater f19092w;

    /* renamed from: x */
    public AbstractC3435a<Unit> f19093x;

    /* renamed from: s */
    public final AbstractC6949c f19088s = Preconditions.m9802P(1, new C4253a(this, null, null));

    /* renamed from: y */
    public ArrayList<String> f19094y = new ArrayList<>();

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView$a */
    /* loaded from: classes2.dex */
    public static final class C4253a extends Lambda implements AbstractC3435a<HashtagService> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19095a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4253a(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19095a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, ri.a] */
        @Override // p189gn.AbstractC3435a
        public final HashtagService invoke() {
            return this.f19095a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(HashtagService.class), null, null);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public WorkTagEditView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(attributeSet, "attributeSet");
        LayoutInflater from = LayoutInflater.from(getContext());
        MutabilityOwnership.m3746l(from, "from(context)");
        this.f19092w = from;
        View inflate = from.inflate(R.layout.view_work_tag_edit, this);
        View findViewById = inflate.findViewById(R.id.tag_container);
        MutabilityOwnership.m3746l(findViewById, "view.findViewById(R.id.tag_container)");
        this.f19089t = (FlexboxLayout) findViewById;
        View findViewById2 = inflate.findViewById(R.id.button_add_tag);
        MutabilityOwnership.m3746l(findViewById2, "view.findViewById(R.id.button_add_tag)");
        AddButton addButton = (AddButton) findViewById2;
        this.f19090u = addButton;
        View findViewById3 = inflate.findViewById(R.id.input_tag);
        MutabilityOwnership.m3746l(findViewById3, "view.findViewById(R.id.input_tag)");
        EditText editText = (EditText) findViewById3;
        this.f19091v = editText;
        addButton.setOnClickListener(new View$OnClickListenerC0158t(this, 19));
        addButton.m4599a();
        editText.setFilters(new InputFilter[]{new InputSpaceFilter()});
        editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { // from class: cj.a
            @Override // android.widget.TextView.OnEditorActionListener
            public final boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                WorkTagEditView.m4604s(WorkTagEditView.this, textView, i, keyEvent);
                return false;
            }
        });
        editText.addTextChangedListener(new p077cj.WorkTagEditView(this));
    }

    public final HashtagService getHashtagService() {
        return (HashtagService) this.f19088s.getValue();
    }

    /* JADX WARN: Code restructure failed: missing block: B:9:0x0017, code lost:
        if ((r4 != null && r4.getKeyCode() == 66) != false) goto L_0x0019;
     */
    /* renamed from: s */
    /* Code decompiled incorrectly, please refer to instructions dump */
    public static boolean m4604s(p270jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView r1, android.widget.TextView r2, int r3, android.view.KeyEvent r4) {
        /*
            java.lang.String r2 = "this$0"
            p325m0.MutabilityOwnership.m3745m(r1, r2)
            r2 = 6
            r0 = 0
            if (r3 == r2) goto L_0x0019
            if (r4 != 0) goto L_0x000c
            goto L_0x0016
        L_0x000c:
            int r2 = r4.getKeyCode()
            r3 = 66
            if (r2 != r3) goto L_0x0016
            r2 = 1
            goto L_0x0017
        L_0x0016:
            r2 = r0
        L_0x0017:
            if (r2 == 0) goto L_0x003d
        L_0x0019:
            android.widget.EditText r2 = r1.f19091v
            android.text.Editable r2 = r2.getText()
            java.lang.String r2 = r2.toString()
            ri.a r3 = r1.getHashtagService()
            boolean r3 = r3.m2577d(r2)
            if (r3 == 0) goto L_0x0031
            r1.m4601v(r2)
            goto L_0x003d
        L_0x0031:
            android.widget.EditText r2 = r1.f19091v
            java.lang.String r3 = ""
            r2.setText(r3)
            android.widget.EditText r1 = r1.f19091v
            r1.requestFocus()
        L_0x003d:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: p270jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView.m4604s(jp.pxv.android.legacy.upload.presentation.view.WorkTagEditView, android.widget.TextView, int, android.view.KeyEvent):boolean");
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    public final int getTagCount() {
        return this.f19094y.size();
    }

    public final ArrayList<String> getTagList() {
        return this.f19094y;
    }

    public final void setOnChangedTagCountListener(AbstractC3435a<Unit> aVar) {
        MutabilityOwnership.m3745m(aVar, "onChangedTagCountListener");
        this.f19093x = aVar;
    }

    /* renamed from: u */
    public final void m4602u() {
        String obj = this.f19091v.getText().toString();
        if (getHashtagService().m2577d(obj)) {
            m4601v(obj);
        }
    }

    /* renamed from: v */
    public final void m4601v(String str) {
        if (this.f19094y.size() >= 10) {
            Toast.makeText(getContext(), (int) R.string.upload_invalid_tag_number, 0).show();
            this.f19091v.setText(str);
            return;
        }
        Objects.requireNonNull(getHashtagService());
        String b = HashtagService.f25843a.m2761b(str, "");
        if (!this.f19094y.contains(b)) {
            this.f19094y.add(b);
            String a = getHashtagService().m2580a(b);
            View inflate = this.f19092w.inflate(R.layout.tag, (ViewGroup) this.f19089t, false);
            ((TextView) inflate.findViewById(R.id.label)).setText(a);
            inflate.setOnClickListener(new View$OnClickListenerC0156s7(this, b, 2));
            this.f19089t.addView(inflate);
            AbstractC3435a<Unit> aVar = this.f19093x;
            if (aVar != null) {
                aVar.invoke();
            }
        }
        this.f19091v.setText("");
        this.f19091v.requestFocus();
    }

    /* renamed from: w */
    public final void m4600w(List<String> list) {
        MutabilityOwnership.m3745m(list, "tagList");
        for (String str : list) {
            if (getHashtagService().m2577d(str)) {
                m4601v(str);
            }
        }
    }
}
